package com.flydust.apipulse.config;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Region;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.logging.Logger;

@Configuration
public class QiniuConfig {

    private static final Logger logger = Logger.getLogger(QiniuConfig.class.getName());

    @Value("${qiniu.accessKey}")
    private String accessKey;

    @Value("${qiniu.secretKey}")
    private String secretKey;

    @Value("${qiniu.bucketName}")
    private String bucketName;

    @Bean
    public Auth auth() {
        logger.info("初始化七牛云Auth配置");
        return Auth.create(accessKey, secretKey);
    }

    @Bean
    public com.qiniu.storage.Configuration qiniuConfiguration() {
        logger.info("初始化七牛云Configuration配置");
        return new com.qiniu.storage.Configuration(Region.huadong()); // 华东区
    }

    @Bean
    public BucketManager bucketManager() {
        logger.info("初始化七牛云BucketManager配置");
        return new BucketManager(auth(), qiniuConfiguration());
    }

    public String getBucketName() {
        return bucketName;
    }
}